package com.wr.mqlistener;

import com.wr.constant.GlobalConstant;
import com.wr.service.ArticleService;
import org.apache.log4j.Logger;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author weirong
 * @Title:
 * @Description:
 * @date 2018/6/1513:36
 */
@Component
public class Receiver {

    Logger logger = Logger.getLogger(this.getClass());
    @Autowired
    private ArticleService articleService;

    @RabbitListener(queues = GlobalConstant.BLOG_VIEW_COUNT_QUEUE)
    public String processBlogViewCount(Integer msg) {
        logger.info(Thread.currentThread().getName() + " 接收到来自"+GlobalConstant.BLOG_VIEW_COUNT_QUEUE+"队列的消息：" + msg);
        try {
            articleService.updateViewCount(msg);
        }catch (Exception e) {
            logger.error(e);
        }
        return String.valueOf(msg);
    }

}
